package  main.java.leetcode.editor.cn;
//2023-07-21 13:56:10
//给定M×N矩阵，每一行、每一列都按升序排列，请编写代码找出某元素。 
//
// 示例: 
//
// 现有矩阵 matrix 如下： 
//
// [
//  [1,   4,  7, 11, 15],
//  [2,   5,  8, 12, 19],
//  [3,   6,  9, 16, 22],
//  [10, 13, 14, 17, 24],
//  [18, 21, 23, 26, 30]
//]
// 
//
// 给定 target = 5，返回 true。 
//
// 给定 target = 20，返回 false。 
// Related Topics 数组 二分查找 分治 矩阵 👍 58 👎 0

class SortedMatrixSearchLcci {
    public static void main(String[] args) {
        //创建该题目的对象方便调用
        Solution solution = new SortedMatrixSearchLcci().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {

        for (int[] arr : matrix){

            int left = 0;
            int right = arr.length-1;

            while (left<=right){
                int mid = (left+right)>>>1;
                if(arr[mid] == target){
                    return true;
                }else if(arr[mid] > target){
                    right = mid-1;
                }else {
                    left = mid+1;
                }
            }

        }

        return false;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
